﻿using System;

namespace DataModel.Models
{
    public partial class Lesson
    {
        /// <summary>
        /// throw DivideByZeroExeption if periodicity equal NULL
        /// </summary>
        /// <param name="periodicity"></param>
        /// <param name="pereodicityMask"></param>
        /// <returns>periodicity Code</returns>
        public static int PeriodicityCode(int periodicity,int pereodicityMask)
        {
            if (periodicity == 0) throw new DivideByZeroException("Periodicity NULL");

            int periodicityCode = pereodicityMask;
            int count = 32 / periodicity;
            for (int i = 0; i < count - 1; i++)
            {
                pereodicityMask <<= periodicity;
                periodicityCode += pereodicityMask;
            }
            return periodicityCode;
        }
    }
}
